package com.shrct.businessprocess.project.impl;

import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.project.RCProjectMoney;
import com.shrct.businessprocess.project.RCProjectProductSale;
import com.shrct.businessprocess.project.RCProjectType;
import com.shrct.businessprocess.project.impl.RCProjectTypeExtensionImpl;
import com.shrct.businessprocess.project.proxy.RCProjectProductSaleProxy;
import edu.fudan.mylang.common.NumberExtensions;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import org.eclipse.xtext.xbase.lib.DoubleExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;

@Entity
@DiscriminatorValue("RCPROJECTPRODUCTSALE_TYPE")
public class RCProjectProductSaleImpl extends RCProjectTypeExtensionImpl implements RCProjectProductSale {
  public RCProjectProductSaleImpl() {
    super();
  }
  
  public void initType() {
    this.setType(RCProjectType.productSale);
  }
  
  public Double calcPercent() {
    double _xblockexpression = (double) 0;
    {
      RCProject _project = this.getProject();
      RCProjectMoney _totalContractAmount = _project.getTotalContractAmount();
      final Double contractAmount = _totalContractAmount.toHostAmount();
      double _xifexpression = (double) 0;
      Double _nullsafe = NumberExtensions.nullsafe(contractAmount);
      boolean _equals = ((_nullsafe).doubleValue() == 0);
      if (_equals) {
        _xifexpression = 0d;
      } else {
        RCProject _project_1 = this.getProject();
        RCProjectMoney _totalInvoiceAmount = _project_1.getTotalInvoiceAmount();
        Double _hostAmount = _totalInvoiceAmount.toHostAmount();
        double _divide = DoubleExtensions.operator_divide(_hostAmount, contractAmount);
        _xifexpression = _divide;
      }
      _xblockexpression = (_xifexpression);
    }
    return Double.valueOf(_xblockexpression);
  }
  
  public Double calcTotalIncome() {
    RCProject _project = this.getProject();
    RCProjectMoney _totalInvoiceAmount = _project.getTotalInvoiceAmount();
    Double _hostAmount = _totalInvoiceAmount.toHostAmount();
    return _hostAmount;
  }
  
  public static RCProjectProductSale create(final IObjectFactory objectFactory) {
    com.shrct.businessprocess.project.RCProjectProductSale rCProjectProductSale = new com.shrct.businessprocess.project.impl.RCProjectProductSaleImpl(
    );
    objectFactory.create(rCProjectProductSale);
    return rCProjectProductSale;			
    
  }
  
  public static RCProjectProductSale createRCProjectProductSaleImpl(final IObjectFactory objectFactory, final Procedure1<RCProjectProductSale> init) {
    com.shrct.businessprocess.project.RCProjectProductSale rCProjectProductSale = new com.shrct.businessprocess.project.impl.RCProjectProductSaleImpl(
    );
    objectFactory.create(rCProjectProductSale);
    init.apply(rCProjectProductSale);
    
    return rCProjectProductSale;			
    
  }
  
  public RCProjectProductSaleProxy toProxy() {
    com.shrct.businessprocess.project.proxy.RCProjectProductSaleProxy proxy = new com.shrct.businessprocess.project.proxy.RCProjectProductSaleProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
